package com.fjp.heartguard.ui.question.fragment

import android.os.Bundle
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import com.fjp.heartguard.app.base.BaseFragment
import com.fjp.heartguard.app.data.bean.Questions
import com.fjp.heartguard.databinding.FragmentInputBinding
import com.fjp.heartguard.viewmodel.InputViewModel

class InputFragment : BaseFragment<InputViewModel, FragmentInputBinding>() {


    companion object {
        fun newInstance(questions: Questions): Fragment {
            val fragment = InputFragment()
            val bundle = Bundle()
            bundle.putSerializable("question", questions)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewmodel = mViewModel
        val questions = arguments?.getSerializable("question") as Questions
        mDatabind.extraDataEt.setText(questions.options[0].value)
        questions.let {
            mDatabind.questionTitleLayout.setType(questions.questionType)
            mDatabind.questionTv.text = it.questionTitle

        }
        mDatabind.extraDataEt.addTextChangedListener {
            questions.options[0].value = it.toString()
        }

    }

}